<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>协会概况</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="${ctxPath}/static/manage/css/x-admin.css" media="all">
    <link rel="stylesheet" href="${ctxPath}/static/manage/layui/css/layui.css" media="all">
    <script src="${ctxPath}/static/manage/layui/layui.js"></script>
    <script src="${ctxPath}/static/manage/js/jquery.js"></script>
</head>
<body>
<div class="x-nav">
        <span class="nav-breadcrumb">
            <a><cite>后台管理></cite></a>
            <a><cite>药品管理></cite></a>
            <a><cite>人员管理</cite></a>
        </span>
</div>
<div class="x-body">

    <table id="pharmacyTable" lay-filter="pharmacyTable"></table>

</div>
</body>
</html>

<script type="text/javascript">
    layui.use(['jquery', 'table', 'layer', 'util'], function(){
        var $ = layui.$, table = layui.table, layer = layui.layer, util = layui.util;
        table.render({
            elem: '#pharmacyTable'
            ,id: 'phtable_id'
            ,height: 500
            ,url: '/manage/pharmacy/findAll'
            ,page: true
            ,limit: 8
            ,limits : [5,10,15,20]
            ,cols: [[
                { checkbox: true, fixed: true },
                { field: 'pid', title: '序号', sort: true},
                { field: 'pname', title: '药库名字' },
                { field: 'pstock', title: '药库描述' },
                { field: 'tempId', title: '操作', width:230, templet: function(d){
                        return '<a class="layui-btn layui-btn-xs" lay-event="read" lay-id="'+ d.tempId +'"><i class="layui-icon layui-icon-read"></i>查看</a>'+
                            '<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del" lay-id="'+ d.tempId +'"><i class="layui-icon layui-icon-del"></i>移除</a>'+
                            '<a class="layui-btn layui-btn-xs" lay-event="edit" lay-id="'+ d.tempId +'"><i class="layui-icon layui-icon-edit"></i>编辑</a>';

                    }}
            ]]
        });
        // 搜索（利用定义的active重新载入表格）
        $('.search_btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        // 监听工具条
        table.on('tool(pharmacyTable)', function (obj) {
            // data当前行数据， lay-event或event 对应的值，当前行tr的DOM对象
            var data = obj.data, event = obj.event;
            console.log(data);
            switch(event){
                case "read":
                    pharmacyRead(data);
                    break;
                case "edit":
                    pharmacyEdit(data);
                    break;
                case "del":
                    pharmacyDel(data);
                    break;
            }
        });
        // 查看
        function pharmacyRead(rowData) {
            layer.open({
                title : "查看" + rowData.pname,
                type : 2,
                fix: false, //不固定
                maxmin: true,
                area: ['1000px', '600px'],
                content: "/manage/pharmacy/toread/" + rowData.pid
            });
        }
        function pharmacyDel(rowData) {
            layer.confirm('真的删除行么？', function(index){
                layer.close(index);
                $.ajax({
                    type: 'post',
                    url: '/manage/pharmacy/deltype/' + rowData.pid,
                    success:function(result){
                        if(result){
                            alert(result);
                            window.location.reload();
                        }else{
                            alert(result);
                        }

                    }
                });
            });
        }
        function pharmacyEdit(rowData) {
            layer.open({
                title : "编辑" + rowData.pname,
                type : 2,
                fix: false, //不固定
                maxmin: true,
                area: ['1000px', '600px'],
                content: "/manage/pharmacy/toedit/" + rowData.pid
            });
        }

    });

</script>
